<template>
	<view>
		<u-navbar title="图片详情" leftIcon="list-dot" @leftClick='left()'></u-navbar>
		<view style="margin-top: 180rpx;">
			<detail :urls="urls" :picTime="picTime" :type="type" :index="index" @sent="sent()" v-if="type!=='大图'"></detail>
			<goodlist :urls="urls" v-if="type==='大图'"></goodlist>
		</view>
		<u-picker :show="show1" :columns="columns"  @confirm="confirm" @cancel="show1=false"
				></u-picker>
	</view>
</template>

<script>
	import goodlist from '../components/goods-list/goods-list.vue'
	import navbox from '../components/navbox/navbox.vue'
	import detail from '../components/detail/detail.vue'
	export default {
		data() {
			return {
				type:'大图',
				show1: false,
				columns: [
					['大图', '小图', '显示时间']
				],
				timer: null,
				total1: '',
				total2: '',
				picTime: [],
				urls: [],
				// show: true,
				pic: [],
				index: 0,
				parm: {
					pageSize: 10,
					pageNum: 1,
					id: ''
				}
			}
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.parm.pageNum = 1
			this.getListTotal()
			this.timer = setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			this.getBottom()
		},
		onLoad(optins) {
			if (this.timer) {
				clearTimeout(this.timer); // 清除定时器  
			}
			uni.showLoading({
				title: '加载中'
			});
			this.index = optins.index
			this.parm.id = optins.id
			this.getListTotal()
		},
		components: {
			"navbox": navbox,
			"detail": detail,
			"goodlist": goodlist
		},
		methods: {
			getListTotal(){
				if (this.type !== "显示时间") {
					this.getlist()
				}else{
					this.getlistT()
				}
			},
			async getlist() {
				if(this.type==="大图"){
					this.parm.pageSize=10
				}else{
					this.parm.pageSize=36
				}
				const res = await this.$myRuquest({
					url: '/wexinLogin/pictures/findPicByPicsId',
					method: 'post',
					data: this.parm
				})
				this.urls = res.data.data.data.records
				this.total1 = res.data.data.data.total
				uni.hideLoading();
			},
			async getlistT() {
				const res = await this.$myRuquest({
					url: '/wexinLogin/pictures/findPicByPicsIdAndtime',
					method: 'post',
					data: this.parm
				})
				console.log(res)
				this.picTime = res.data.data.data.records
				this.total2 = res.data.data.data.total
				uni.hideLoading();
			},
			confirm(e) {
				this.type=e.value[0]
				this.show1 = false
				this.parm.pageNum=1
				this.getListTotal()
				console.log(this.type)
			},
			async getBottom() {
				const that = this
				if (this.type !== "显示时间") {
					if (this.urls.length < this.total1) {
						this.parm.pageNum++
						uni.showLoading({
							title: '加载中'
						});
						if(this.type==="大图"){
							this.parm.pageSize=10
						}else{
							this.parm.pageSize=36
						}
						uni.request({
							url: that.$baseurl + "/wexinLogin/pictures/findPicByPicsId",
							method: 'POST',
							data: that.parm,
							success(res) {
								that.urls = [...that.urls, ...res.data.data.data.records]
							}
						})
						uni.hideLoading();
					}
				} else {
					if (this.picTime.length < this.total2) {
						this.page.pageNum++
						uni.showLoading({
							title: '加载中'
						});
						uni.request({
							url: that.$baseurl + "/wexinLogin/pictures/findPicByPicsIdAndtime",
							method: 'POST',
							data: that.parm,
							success(res) {
								that.picTime = [...that.picTime, ...res.data.data.data.records]
							}
						})
						uni.hideLoading();

					}
				}
			},
			left() {
				this.show1=true
				// this.show = !this.show
				if (this.show === true) {
					this.getlist()
				} else {
					this.getlistT()
				}

			},
			sent() {
				this.getlist()
			},

		}
	}
</script>

<style>

</style>
